# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
### BEGIN LICENSE
# This file is in the public domain
### END LICENSE

import gettext
from gettext import gettext as _
gettext.textdomain('ninjabrowser')

from gi.repository import Gtk, WebKit # pylint: disable=E0611
import logging
logger = logging.getLogger('ninjabrowser')

from ninjabrowser_lib import Window
from ninjabrowser.AboutNinjabrowserDialog import AboutNinjabrowserDialog
from ninjabrowser.PreferencesNinjabrowserDialog import PreferencesNinjabrowserDialog

# See ninjabrowser_lib.Window.py for more details about how this class works
class NinjabrowserWindow(Window):
    __gtype_name__ = "NinjabrowserWindow"
    
    def finish_initializing(self, builder): # pylint: disable=E1002
        """Set up the main window"""
        super(NinjabrowserWindow, self).finish_initializing(builder)

        self.AboutDialog = AboutNinjabrowserDialog
        self.PreferencesDialog = PreferencesNinjabrowserDialog

        # Code for other initialization actions should be added here.

        self.refresh = self.builder.get_object("refresh")
        self.back = self.builder.get_object("back")
        self.forward = self.builder.get_object("forward")
        self.home = self.builder.get_object("home")
        self.urlentry = self.builder.get_object("urlentry")
        self.scrolledwindow = self.builder.get_object("scrolledwindow")
        self.toolbar = self.builder.get_object("toolbar")

        context = self.toolbar.get_style_context()
        context.add_class(Gtk.STYLE_CLASS_PRIMARY_TOOLBAR)

        self.webview = WebKit.WebView()

        self.scrolledwindow.add(self.webview)
        self.webview.show()
        self.webview.open("http://google.com")

    def on_refresh_clicked(self, widget):
        self.webview.reload()

    def on_back_clicked(self, widget):
        self.webview.go_back()

    def on_foward_clicked(self, widget):
        self.webview.go_forward()
    
    def on_home_clicked(self, widget):
        self.webview.open("http://google.com")

    def on_urlentry_activate(self, widget):
        url = widget.get_text()

        self.webview.open(url)


